package com.qingneng.budget.web;

import com.opensymphony.xwork2.Action;
import com.qingneng.budget.service.sdk.IUserInfoService;
import com.qingneng.budget.util.BaseAction;
import com.qingneng.budget.util.DigestUtils;
import com.qingneng.budget.vo.Userinfo;

public class AdminAction extends BaseAction {
	private String message;

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String modifyPwd() {
		String oldpwd = getRequest().getParameter("oldpwd");
		String newpwd1 = getRequest().getParameter("newpwd1");
		String newpwd2 = getRequest().getParameter("newpwd2");
		if (oldpwd == null || newpwd1 == null || newpwd2 == null) {
			message = "密码不能为空！";
			return Action.SUCCESS;
		}
		if (!newpwd1.equals(newpwd2)) {
			message = "新密码和确认密码不一样";
			return Action.SUCCESS;
		}
		IUserInfoService userService = (IUserInfoService)getBean(IUserInfoService.class);
		Userinfo userinfo = getUserInfo();
		if(DigestUtils.md5Hex(oldpwd).equals(userinfo.getUserpassword())){
			userinfo.setUserpassword(DigestUtils.md5Hex(newpwd1));
			if(userService.modify(userinfo)>0){
				setUserInfo(userinfo);
				message = "success";
			}else{
				message = "修改密码失败！";
			}
			
		}else{
			message = "旧密码不正确！";
		}
		return Action.SUCCESS;
	}
}
